<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 用户权限列表卡片 -->
    <el-card>
      <el-table :data="authList" border stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="权限名称" prop="authName"></el-table-column>
        <el-table-column label="路径" prop="authPath"></el-table-column>
        <el-table-column label="权限等级" prop="authLevel">
          <template v-slot="scope">
            <el-tag v-if="scope.row.authLevel === 1">一级</el-tag>
            <el-tag type="success" v-else-if="scope.row.authLevel === 2"
              >二级</el-tag
            >
            <el-tag type="warning" v-else>三级</el-tag>
          </template>
        </el-table-column>
      </el-table>

      <!--分页插件-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageParam.pageNo"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="pageParam.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 分页数据
      pageParam: {
        pageSize: 5,
        pageNo: 1,
        param: {}
      },
      // 总共条数
      total: 0,

      authList: []
    };
  },
  created() {
    this.getAuthList();
  },
  methods: {
    //获取用户列表数据请求
    async getAuthList() {
      const { data: res } = await this.$http.post("auth/page", this.pageParam);
      if (res.meta.code !== 200) {
        return this.$message.error("获取管理员列表失败!");
      }

      this.authList = res.data.records;
      this.total = res.data.total;
      console.log(res);
    },

    // 当前页显示条数发生改变触发事件
    handleSizeChange(newSize) {
      this.pageParam.pageSize = newSize;
      this.getAuthList();
    },

    // 当前页发生改变触发函数
    handleCurrentChange(newNum) {
      console.log(newNum);
      this.pageParam.pageNo = newNum;
      this.getAuthList();
    }
  }
};
</script>

<style></style>
